package com.ht.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
import javax.validation.constraints.NotEmpty;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ht.system.mapper.CustomsMapper;
import com.ht.common.core.constant.Constants;
import com.ht.common.core.utils.StringUtils;
import com.ht.system.api.dto.DictDataDto;
import com.ht.system.api.dto.DictDto;
import com.ht.system.component.InitDictCommonComponent;
import com.ht.system.domain.Customs;
import com.ht.system.service.ICustomsService;

/**
 * 关区代码Service业务层处理
 * 
 * @author zmx
 * @date 2025-03-22
 */
@Service
public class CustomsServiceImpl implements ICustomsService 
{
    @Autowired
    private CustomsMapper customsMapper;
    @Autowired
    private InitDictCommonComponent initDictCommonComponent;

    
    @PostConstruct
    public void customsToDict(){
    	List<Customs>  cusList=customsMapper.selectCustomsList(new Customs());
    	if(StringUtils.isNotEmpty(cusList)){
    		DictDto dictDto=new DictDto();
    		dictDto.setDictType(Constants.ENTITY_TO_DICT_PRE+"customs");
    		dictDto.setDictName("关区信息字典");
    		List<DictDataDto> dictDataList= cusList.stream().map(n->new DictDataDto(n.getCustomsCode(),n.getCustomsName(),"1")).collect(Collectors.toList());
    		dictDto.setDictDataList(dictDataList);
    		initDictCommonComponent.add(dictDto);
    	}
    }
    
    
    /**
     * 查询关区代码
     * 
     * @param customsCode 关区代码主键
     * @return 关区代码
     */
    @Override
    public Customs selectCustomsByCustomsCode(String customsCode)
    {
        return customsMapper.selectCustomsByCustomsCode(customsCode);
    }

    /**
     * 查询关区代码列表
     * 
     * @param customs 关区代码
     * @return 关区代码
     */
    @Override
    public List<Customs> selectCustomsList(Customs customs)
    {
        return customsMapper.selectCustomsList(customs);
    }

    /**
     * 新增关区代码
     * 
     * @param customs 关区代码
     * @return 结果
     */
    @Override
    public int insertCustoms(Customs customs)
    {
        return customsMapper.insertCustoms(customs);
    }

    /**
     * 修改关区代码
     * 
     * @param customs 关区代码
     * @return 结果
     */
    @Override
    public int updateCustoms(Customs customs)
    {
        return customsMapper.updateCustoms(customs);
    }

    /**
     * 批量删除关区代码
     * 
     * @param customsCodes 需要删除的关区代码主键
     * @return 结果
     */
    @Override
    public int deleteCustomsByCustomsCodes(@NotEmpty(message="参数不能为空") String[] customsCodes)
    {
		
    	int delRes=0;
    	for (String id : customsCodes) {
    		delRes+=deleteCustomsByCustomsCode(id);
		}
        return delRes;
    }

    /**
     * 删除关区代码信息
     * 
     * @param customsCode 关区代码主键
     * @return 结果
     */
    public int deleteCustomsByCustomsCode(String customsCode)
    {
        return customsMapper.deleteCustomsByCustomsCode(customsCode);
    }
}
